package Algorithm.Sort.FastSort;

public class Example {
    public static void main(String[] args) {
        int[] arr = {4, 9, 2, 6, 5, 1, 3, 8, 7};
        fastSort(arr, 0, arr.length - 1);
        for (int j : arr) {
            System.out.println(j);
        }
    }
    public static void fastSort(int[] arr, int i, int j){
        if (i >= j)
            return;
        int start = i, end = j;
        int basicNum = arr[i];
        while(start < end){
            while (end > start && arr[end] >= basicNum) {
                end--;
            }
            while (end > start && arr[start] <= basicNum) {
                start++;
            }
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }
        int temp = arr[start];
        arr[start] = arr[i];
        arr[i] = temp;
        fastSort(arr, i, start - 1);
        fastSort(arr, start + 1, arr.length - 1);
    }
}